package com.fubang.pathlearning.path.radar;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 创建者: YIN
 * 创建时间: 2017/7/5 13:48
 * 电子邮箱: yin_ruimin@foxmail.com
 * 描述:
 */

public class PathTestView extends View {

    private Paint mBlackPaint;
    private int mWidth;
    private int mHeight;

    public PathTestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        mBlackPaint = new Paint();
        mBlackPaint.setColor(Color.BLACK);
        mBlackPaint.setStrokeWidth(10);
        mBlackPaint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        this.mWidth = w;
        this.mHeight = h;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mWidth / 2, mHeight / 2);
        Path path = new Path();
//        path.lineTo(200,200);
//        path.setLastPoint(200,100);
//        path.lineTo(200,0);
//        path.close();
//        canvas.drawPath(path, mBlackPaint);

//        path.addRect(-200, -200, 200, 200, Path.Direction.CCW);//CW clockwise顺时针 CCW counterclockwise
//        path.setLastPoint(-100, 100);//设置矩形组后一个点的位置
//        canvas.drawPath(path, mBlackPaint);

        Path src = new Path();
        path.addRect(-200,-200,200,200, Path.Direction.CW);
        src.addCircle(0,0,100, Path.Direction.CW);
        path.addPath(src,0,-200);
        canvas.drawPath(path,mBlackPaint);

    }
}
